// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#pragma once

#include <pollux/dwio/common/selective_column_reader.h>
#include <pollux/dwio/parquet/reader/parquet_data.h>

namespace kumo::pollux::parquet {
    class StringColumnReader : public dwio::common::SelectiveColumnReader {
    public:
        using ValueType = StringView;

        StringColumnReader(
            const std::shared_ptr<const dwio::common::TypeWithId> &fileType,
            ParquetParams &params,
            common::ScanSpec &scanSpec);

        bool hasBulkPath() const override {
            //  Non-dictionary encodings do not have fast path.
            return !formatData_->as<ParquetData>().isDeltaByteArray() &&
                   scanState_.dictionary.values != nullptr;
        }

        void seekToRowGroup(int64_t index) override {
            SelectiveColumnReader::seekToRowGroup(index);
            scanState().clear();
            readOffset_ = 0;
            formatData_->as<ParquetData>().seekToRowGroup(index);
        }

        uint64_t skip(uint64_t numValues) override;

        void read(int64_t offset, const RowSet &rows, const uint64_t *incomingNulls)
        override;

        void getValues(const RowSet &rows, VectorPtr *result) override;

        void dedictionarize() override;
    };
} // namespace kumo::pollux::parquet
